﻿using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class CFExFilterParams : CFExTemplateParams
    {
        private bool fTop;
        private bool fPercent;
        private ushort iParam;
        private byte[] reserved2 = new byte[13];

        public override void Read(BinaryReader reader)
        {
            byte ab = reader.ReadByte();
            this.fTop = (ab & 0x01) != 0;
            this.fPercent = (ab & 0x02) != 0;
            Contract.Assert(this.Ab == ab);
            this.iParam = reader.ReadUInt16();
            this.reserved2 = reader.ReadBytes(13);
        }

        protected byte Ab
        {
            get { byte result = 0;
            if (fTop)
                result |= 0x01;
            if (fPercent)
                result |= 0x02;
                return result;
            }
        }

        public override void Write(BinaryWriter writer)
        {
            writer.Write(Ab);
            writer.Write(this.iParam);
            writer.Write(this.reserved2);
        }

        public override byte Type
        {
            get { return 0x05; }
        }

        public override byte Length
        {
            get { throw new NotImplementedException(); }
        }
    }
}